<template>
  <el-row
    class="dasdads"
    type="flex"
    justify="space-between"
    align="middle"
    style="width: 100%; height: 40px"
  >
    <el-col :span="8">
      <strong v-if="isCompany">{{ treeData.name }}</strong>
      <span v-else>{{ treeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end" style="width:150px">
        <!-- 两个内容 -->
        <el-col>{{ treeData.manager==='管理员'?'':treeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('handleOpen',treeData.id)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="$emit('handleOpen',treeData.id,'update')">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="del(treeData.id)">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartrment } from '@/api/departments'

export default {
  name: 'TreeTool',
  props: {
    isCompany: {
      type: Boolean,
      required: true
    },
    treeData: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 删除
    async  del(id) {
      try {
        await this.$confirm('你确定要删除吗？')
        await delDepartrment(id)
        this.$message.success('删除成功')
        this.$emit('render')
      } catch (error) {
        this.$message.warning(' 取消删除')
      }
    }
  }

}
</script>

<style scoped>
</style>
